#! /bin/bash

#cd ../../
#vole=`$PWD`
vole="/home/rong/code/vole"
cd $vole
echo "切换到目录$vole"
git pull
echo "更新项目至最新"
mvn clean package
echo "vole 工程目录进行编译打包..."

# ensure $jar exists
jar=/data/jar
if [ ! -d $jar ]
then
   mkdir -p $jar
fi
sudo chmod a+w $jar
modules=('vole-eureka' 'vole-config' 'vole-portal-data' 'vole-portal' 'vole-passport' 'vole-mps' 'vole-auth' 'vole-gateway')
for md in ${modules[@]}
do
  echo "开始处理模块${md}"
  vole_jar=$md/target/${md}.jar
  if [ ! -f $vole_jar  ]
  then
    echo "${vole_jar}不存在，异常退出"
    return
  fi
  cp $vole_jar $jar
  if [ -f $jar/${md}.jar ]
  then
    echo "复制${vole_jar} 至 $jar 完成"
  else
    echo "复制${vole_jar} 至 $jar 失败，异常退出"
    return
  fi
done

echo "所有模块的编译打包到$jar 完成"

echo "开始启动微服务..."

cd $vole/docs/docker
docker-compose down && docker-compose up -d  

echo "请耐性等待2分钟左右..."

